package com.hxgis.oc.product.w3d;

import com.hxgis.oc.product.base.ConvertTask;
import com.hxgis.oc.util.w3d.base.W3dConvert;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.IOException;

@Slf4j
@Getter
@Setter
public class W3dConvTask extends ConvertTask {
    protected String varName;

    public W3dConvTask(Long workID,String ds,File fileToConvert,String var) {
        super(workID,ds);
        inputFile = fileToConvert;
        varName = var;
        productType = W3dProductManager.getFactoryName();
    }

    @Override
    public boolean producing() {
        boolean succeed = false;

        try {
            succeed = W3dConvert.convert(inputFile, outputFile,varName) && outputFile.exists();
        } catch (IOException | InterruptedException e) {
            log.error(e.getMessage());
        }
        finally {
            if(!succeed){
                retrieve();
            }
        }
        return succeed;
    }
}
